package com.weiyin.examination.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.TextView;

import com.weiyin.examination.R;
import com.weiyin.examination.util.LayoutHelper;

import org.apache.commons.lang3.StringUtils;

/**
 * <pre>
 *     e-mail : niejunfeng@win-electr.com
 *     time   : 2018/04/25
 *     desc   : 判断是否跳过听力
 *     version: 1.0.0
 *     Copyright: Copyright（c）2017
 *     Company:上海蔚音电子科技有限公司
 * </pre>
 *
 * @author niejunfeng
 */
public class CourseDialog extends Dialog implements View.OnClickListener {
    private Activity activity;
    private TextView textView;
    private String content;

    public CourseDialog(@NonNull Activity context, @StyleRes int themeResId,String text) {
        super(context, themeResId);
        this.activity = context;
        this.content = text;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.course_dialog_layout);
        LayoutHelper layoutHelper = new LayoutHelper(activity);
        layoutHelper.scaleView(findViewById(R.id.courseDialogLayout));

        initView();
    }

    private void initView() {
        TextView noDropOut = (TextView) findViewById(R.id.noDropOut);
        TextView dropOut = (TextView) findViewById(R.id.dropOut);
        textView = findViewById(R.id.dialogTextView);
        if (!StringUtils.isEmpty(content)){
            textView.setText(content);
        }
        noDropOut.setOnClickListener(this);
        dropOut.setOnClickListener(this);
    }



    public interface CourseDialogListener {
        void courseDialogResult(int type);
    }

    private CourseDialogListener courseDialogListener;

    public void setCourseDialogInterlisteren(CourseDialogListener courseDialogListener) {
        this.courseDialogListener = courseDialogListener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.noDropOut:
                if (courseDialogListener != null) {
                    courseDialogListener.courseDialogResult(0);
                }
                cancel();
                break;
            case R.id.dropOut:
                if (courseDialogListener != null) {
                    courseDialogListener.courseDialogResult(1);
                }
                cancel();
                break;
            default:
                break;
        }
    }
}
